let houseId

Page({
  data: {
    dialogVisible: false,
    //房屋列表
    houseList: []
  },

  async onLoad() {
    this.gethouseList()
  },
  async gethouseList() {
    const res = await wx.http({
      url: '/room'
    })
    // console.log(res);
    this.setData({
      houseList: res.data
    })
  },
  swipeClose(ev) {
    //显示对话框
    this.setData({
      dialogVisible: true
    })
    const { position, instance } = ev.detail
    //关闭小滑块
    instance.close()
    //获取当前点击删除的id
    houseId = ev.mark.id
    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })
      // swiper-cell 滑块关闭
      instance.close()
    }
  },
  async dialogClose(ev) {
    if (ev.detail === 'confirm') {
      const res = await wx.http({
        url: '/room/' + houseId,
        method: 'delete'
      })
      console.log(res);
      this.gethouseList()
    } else {
      console.log('取消删除');
    }

  },
  //跳转到详情页面
  goDetail(ev) {
    //
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + ev.mark.id
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
